/**
 * Created by xuweijie on 17-5-18.
 */
$(function () {
    $('#commitpwd').click(function () {
        var oldpassword=$('#oldpassword').val();
        var newpassword=$('#newpassword').val();
        var checkpassword=$('#checkpassword').val();
        var flag=validupdatepwd(oldpassword,newpassword,checkpassword);
        if(flag===1){
            alert("三个选框必填");
        }else if(flag===2){
            alert("新密码与确认密码要一致");
        }else {
            var params = $.param({
                oldpassword: oldpassword,
                newpassword: newpassword
            }, true);
            $.ajax({
                url: '/cusupdatepwd.action',
                type: 'post',
                data: params,
                dateType: 'json',
                success:function (data) {
                    if(data=="0"){
                        alert("密码修改成功，请使用新密码登录");
                        window.location.href = "/front/frontlogin";
                    }else {
                        alert("旧密码验证不匹配。请重新输入");
                    }
                }
            });
        }
    })
});

function validupdatepwd(oldpassword,newpassword,checkpassword) {
    var flag=0;
    if(oldpassword==="" || newpassword==="" ||checkpassword===""){
        flag=1;
    }else if(newpassword!==checkpassword){
        flag=2;
    }
    return flag;
}